<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html>
<head>
<title>My JSP 'questionpage.jsp' starting page</title>
<link href="img/ico.ico" rel="shortcut icon">

<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript" src="js/jquery-min.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
.questionName {
	padding-left: 20%;
}

.answersOfQ {
	padding-left: 20%;
}

.newAnswer {
	padding-left: 20%;
}

.filesOfQuestion {
	padding-left: 20%;
}

.questionLink {
	cursor: pointer;
}

.pagetitle {
	padding-left: 10%;
}
</style>
</head>
<body>
	<%@ include file="pagetop/pagetitle.jsp"%>
	<div class="pagetitle">
		<i class="icon-home"></i><a href="index.action">回主页</a>&gt;&gt;&gt;&gt;&gt;<i
			class="icon-question-sign"></i><a class="questionLink">${question.questionname}</a>
	</div>
	<hr />


	<div class="questionName">
		<c:if test="${not empty user}">
			<c:if test="${question.user.id==user.id||user.role=='admin'}">	
		   	<i class="icon-comment"></i> 问题名称：<a title="点击链接进行问题的编辑"
					href="editQuestion.action?questionId=${question.id}">${question.questionname}</a><span style="color:#999">【${question.user.username}】--所属${question.questiontype.name}</span><br />
			</c:if>
			<c:if test="${question.user.id!=user.id&&user.role!='admin'}">	
			<i class="icon-comment"></i>    问题名称：<span>${question.questionname}</span>【${question.user.username}】--所属${question.questiontype.name}<br />
			</c:if>
		</c:if>
		<c:if test="${empty user}">
	    	<i class="icon-comment"></i>问题名称：<span>${question.questionname}</span>【${question.user.username}】--所属${question.questiontype.name}<br />
		</c:if>
	</div>
	<div class="answersOfQ">
		相关答案 <br />
		<c:forEach var="answer" items="${question.answerses}"
			varStatus="status">
			<div>
				<c:if test="${not empty user}">
					<c:if
						test="${user.role=='admin'||user.role=='clinical'||user.id==answer.user.id}">
						<c:if test="${answer.state!='审核通过' }">
					    	&nbsp;&nbsp;&nbsp;答案${status.count}:<a title="点击编辑答案"
									href="editAnswer.action?answerId=${answer.id}">${answer.content}</a>&nbsp;&nbsp;&nbsp;
				    				<a class="deleteAnswersById" href="javascript:viod(0)">删除
				    					<input type="hidden" value="${answer.id}"/>
				    				</a>
							<span style="margin-left: 20px;color: #999;">${answer.user.username}&nbsp;&nbsp;回答,答案${answer.state}</span>
						</c:if>
						<c:if test="${answer.state=='审核通过'}">
				    	&nbsp;&nbsp;&nbsp;答案${status.count}:<span>${answer.content}</span>
							<span style="margin-left: 20px;color: #999;">${answer.user.username}&nbsp;&nbsp;回答,答案${answer.state}</span>
						</c:if>
					</c:if>
					<c:if test="${user.role!='admin'&&user.id!=answer.user.id}">
			    	&nbsp;&nbsp;&nbsp;答案${status.count}:<span>${answer.content}</span>
						<br />
						<span style="margin-left: 20px;color: #999;">${answer.user.username}&nbsp;&nbsp;回答,答案${answer.state}</span>
					</c:if>
					<br />
				</c:if>
				<c:if test="${empty user}">
		    		&nbsp;&nbsp;&nbsp;答案${status.count}:<span>${answer.content}</span>
					<br />
					<span style="margin-left: 20px;color: #999;">${answer.user.username}&nbsp;&nbsp;回答,答案${answer.state}</span>
				</c:if>
			</div>
		</c:forEach>
	</div>
	<div class="newAnswer">
		<c:if test="${not empty user}">
			<i class="icon-pencil"></i>  我来回答：<br />
			<textarea rows="" cols="" name="content"></textarea>
			<span class="tishi1"></span>
			<input type="hidden" name="questionId" value="${question.id}" />
			<br />
			<%--<input type="button" class="icon-pencil" value="我来回答" />
			--%>
			<a type="btn" class="btn replyAnswer" href="javascript:viod(0)"><i
				class="icon-pencil"></i>&nbsp;我来回答</a>
		</c:if>
		<c:if test="${empty user}">
			<span>您还没登录....去</span>
			<a href="login.action?task=login">登录</a>
		</c:if>
	</div>
	<div class="filesOfQuestion">
		<c:if test="${not empty user}">
			<i class="icon-upload"></i>
			<a href="uploadFile.action?questionId=${question.id}">上传新文件</a>
			<br />
			<c:forEach var="files" items="${question.questionFilesRels}"
				varStatus="state">
				<i class="icon-file"></i>文件${state.count}:
				
				<a class="preview" id="preview${files.files.id}" title="文件暂时还没有预览"
					href="gotoPreviewPage.action?fileId=${files.files.id}&&questionId=${question.id}">
					${files.files.filename} <input class="filePreId" type="hidden"
					value="${files.files.id}" /> <input class="filePreUrl"
					type="hidden" value="${files.files.fileurl}" /> </a>
				
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				${files.files.filesize}
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				
				<c:if test="${not empty user&&user.role!='sales'}">
					<c:if test="${user.id==files.files.user.id||user.role=='admin'}">
						<i class="icon-edit"></i>
						<a title="点击编辑文件名" class="editFileName"
							id="editFile${files.files.id}" href="javascript:void(0)"> <input
							type="hidden" class="filesFilesId" value="${files.files.id}" />
							<input type="hidden" class="filesFilesName"
							value="${files.files.filename}" /> 编辑文件名 </a>
						<c:if test="${user.role=='admin'&&question!=null}">

							<i class="icon-trash"></i>
							<a href="javascript:void(0)" class="deleteFileOfQ"
								id="deleteF${files.files.id}"> 删除文件 <input type="hidden"
								name="fileId" value="${files.files.id}" /> <input type="hidden"
								name="questionId" value="${question.id}" /> </a>
						</c:if>
						<span id="editFileSuccessTishi${files.files.id}"></span>
					</c:if>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class="icon-download"></i>
					<a title="点击链接下载" href="downfile.action?fileId=${files.files.id}">点击下载</a>
				</c:if>
				<c:if test="${not empty user&&user.role=='sales'}">

					<span>下载请联系 <c:if test="${files.files.user.username!='权小芳'}">${files.files.user.username}或权小芳
						</c:if> <c:if test="${files.files.user.username=='权小芳'}">权小芳
						</c:if> </span>
				</c:if>
				<div style="padding-left:10%;color: #999;">---${files.files.user.username}于${files.files.uploadtime}上传</div>
				<br />
			</c:forEach>
		</c:if>
	</div>
	<hr />
</body>
<script type="text/javascript">
	$(function(){
		$(".deleteAnswersById").click(function(){
			var c = confirm("您确实要删除该未审核通过的答案？");
			if(c==true){
				/*alert($(this).parents(".ansss"));//ob.parentNode.parentNode.removeChild(ob.parentNode);
				var ns = $(this).parents(".ansss");
				ns.parentNode.removeChild(ns.parentNode);*/
				//$(this).parents("div").removeChild(this.parentNode.parentNode);
				$.post("deleteAnswers.action",{"answerId":$(this).children("input[type='hidden']").val()},function(){
					//$(this).parents("div").removeChild(this.parentNode.parentNode);
					window.location.reload(true);
					window.location.reload(true);
				});
			}
			//deleteAnswers.action?answerId=${answer.id}
		});
	});


	$(function() {
		$(".deleteFileOfQ").each(
			function() {
				var fileId = $(this).children(
						"input[name='fileId']").val();
				var questionId = $(this).children(
						"input[name='questionId']").val();
				$("#deleteF" + fileId).click(function() {
					var c = confirm("您确定要删除该文件吗?");
					if (c == true) {
						$.post("deleteFileInQuestionPage.action", {
							"fileId" : fileId,
							"questionId" : questionId
						});
						
						window.location.reload(true);
					} else {
						return false;
					}
				});
			});
	});

	$(function() {
		$(".editFileName").each(function() {
			var id = $(this).children(".filesFilesId").val();
			var oldFileName = $(this).children(".filesFilesName").val();
			$("#editFile" + id).click(function() {
				var name = prompt("请您输入文件名字：",oldFileName);
				if (name != null && name != "") {
					$.post("editFileName.action",{
						"fileId" : id,
						"questionId" : $("input[name='questionId']").val(),
						"filename" : name
					},
					function(data) {
						window.location.reload(true);
						$(this).siblings("#editFileSuccessTishi" + id).text("修改成功！");
							$("#editFileSuccessTishi" + id).css("color","red");
							$("#editFileSuccessTishi" + id).slideDown("slow",
								function() {
									$("#editFileSuccessTishi" + id).text("");
							});
					});
				} else {
					return false;
				}
			});

		});
	});

	$(function() {
		//location.reload(true); 
		$("textarea").focus(function() {
			$(".tishi1").text("");
		});
		$(".replyAnswer").click(function() {
			if ($("textarea").val().trim() == "") {
				$(".tishi1").text("您还没输入任何东西");
				$(".tishi1").css("color", "red");
				return false;
			}
			$.post("saveAnswersBy.action", {
				"content" : $("textarea").val(),
				"questionId" : $("input[name='questionId']").val()
			});
			window.location.reload(true);
			$(".tishi1").css("color","red");
			$(".tishi1").text("添加成功!");
			$(".tishi1").slideDown("slow"); 
			
		});
		$(".questionLink").click(function() {
			window.location.reload(true);
		});
	});
</script>
</html>
